/**
 * Created by Admin on 30.12.2014.
 */

var LoadingTree = (function ($) {

    return $.inherit(LoadingQueue, {
        results: {},
        options: {
            metaData: 0
        },

        __constructor: function (queuesData, options) {
            this.results = {};
            this.options = $.extend({}, this.options, options)
            var tasks = {};
            var loadingTree = this;
            $.each(queuesData, function (task, queueDatum) {
                tasks[task] = {
                    execute: function (success) {
                        queueDatum.queue.load(function (result) {
                            var taskResult = {
                                result: result,
                                metaData: loadingTree.metaData
                            };
                            loadingTree.results[task] = taskResult;
                            success(taskResult);
                        });

                    },

                    metaData: queueDatum.metaData
                }
            });

            this.__base(tasks);

        }
    }, {})

})(window["jQuery"]);